//
//  BaseView.m
//  滴滴快拍
//
//  Created by dllo on 16/5/18.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "BaseView.h"

@implementation BaseView

- (instancetype)initWithFrame:(CGRect)frame {
    self= [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}



- (void)saveData:(id)data DataName:(NSString *)DataName {
    // 沙盒路径
    //    NSString *sandBoxPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 1, YES) lastObject];
    // 创建一个文件管理器
    NSFileManager *manager = [NSFileManager defaultManager];
    // 拼接一个文件夹路径
    NSString *BagPath = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Caches/MyCache"];
//    NSLog(@"%@", BagPath);
    // 创建文件夹
    [manager createDirectoryAtPath:BagPath withIntermediateDirectories:YES attributes:nil error:nil];
    //  存Data的文件路径
    NSString *DataFilePath = [BagPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist", DataName]];
    // 归档
    [NSKeyedArchiver archiveRootObject:data toFile:DataFilePath];
}



- (NSDictionary *)getDataWithDataName:(NSString *)dataName {
    // 沙盒路径 //NSHomeDirectory()
    //    NSString *sandBoxPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 1, YES) lastObject];
    // 拼接文件夹路径
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Caches/MyCache"];
    // 文件名
    NSString *fileName = [NSString stringWithFormat:@"%@.plist",dataName];
    
    NSString *filePath = [path stringByAppendingPathComponent:fileName];
    
    NSDictionary *cacheDic = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
    
    return cacheDic;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
